const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');

const app = express();



let corsOptions = {
    origin: '*'
}

app.use(cors(corsOptions));
// content-type：application/json
app.use(bodyParser.json());

// content-type：application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));

const db = require("./app/models");
db.sequelize.sync();

require("./app/routers/todo.router")(app);

// 默认路由
app.get('/', (req, res) => {
    res.json({ message: '欢迎访问卡拉云后端服务器！'})
})

// 设置监听端口
const PORT = process.env.PORT || 9025;
app.listen(PORT, () => {
    console.log(`服务器运行在端口: ${PORT}`);
})